import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '@/views/Login/Login.vue'
import Reg from '@/views/Reg/Reg.vue'
import Main from '@/views/Main/Main.vue'
import Home from '@/views/Menu/Home/Home.vue'
import Userinfo from '@/views/Menu/User/UserInfo.vue'
import UserAvatar from '@/views/Menu/User/UserAvatar.vue'
import UserPwd from '@/views/Menu/User/UserPwd.vue'
import ArtCate from '@/views/Menu/ArtCate/ArtCate.vue'
import ArtList from '@/views/Menu/ArtCate/ArtList.vue'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch((err) => err)
}

const routes = [
  { path: '/login', name: 'Login', component: Login },
  { path: '/reg', name: 'Reg', component: Reg },
  {
    path: '/',
    name: 'Main',
    component: Main,
    // 配置重定向，让用户每次访问首页的时候渲染home页面
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: Home
      },
      {
        path: 'user-info',
        name: 'Userinfo',
        component: Userinfo
      },
      {
        path: 'user-avatar',
        name: 'Useravatar',
        component: UserAvatar
      },
      {
        path: 'user-pwd',
        name: 'UserPwd',
        component: UserPwd
      },
      {
        path: 'art-cate',
        name: 'ArtCate',
        component: ArtCate
      },
      {
        path: 'art-list',
        name: 'ArtList',
        component: ArtList
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
